package com.healthcloud.controller.modules.serviceLocation;

import java.util.List;

import com.healthcloud.entity.MsgVo;
import com.healthcloud.entity.serviceLocation.ServiceLocationEntity;
import com.healthcloud.service.serviceLocation.ServiceLocationService;
import com.healthcloud.utils.ApiRes;
import com.healthcloud.utils.PageParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;



/**
 * 检验所服务地址对照
 * 
 * @author yucl
 * @email yucailong1111@126.com
 * @date 2018-08-27 13:16:59
 */
@Controller
@RequestMapping("servicelocation")
public class ServiceLocationController {

	@Autowired
	private ServiceLocationService serviceLocationService;
	
	/**
	 * 列表
	 */
	@ApiOperation(value = "跳转至列表页", notes = "跳转至列表页")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String list(){
	    return "bus/servicelocation/serviceLocationMgr";
	}

    @ApiOperation(value = "列表信息", notes = "列表信息")
    @RequestMapping(value = "/searchServiceLocation", method = RequestMethod.POST)
	@ResponseBody
    public MsgVo searchServiceLocation(ServiceLocationEntity bean, @ModelAttribute("pageParam")PageParam pageParam){
        List<ServiceLocationEntity> list = serviceLocationService.queryList(bean, pageParam);
        int count = serviceLocationService.queryTotal(bean);
        return new MsgVo(list,count,count,pageParam.getsEcho());
    }
	
	/**
	 * 新增页
	 */
    @ApiOperation(value = "跳转至新增页", notes = "跳转至新增页")
	@RequestMapping(value = "/toSave", method = RequestMethod.GET)
    public String toSave() {
        return "bus/servicelocation/addOrUpdateServiceLocation";
    }
    
	/**
	 * 保存
	 */
    @ApiOperation(value = "新增信息", notes = "新增信息")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public ApiRes save(ServiceLocationEntity entity) {
        serviceLocationService.save(entity);
        return ApiRes.SUCCESS;
    }
	
	/**
	 * 修改页
	 */
	@ApiOperation(value = "跳转至修改页", notes = "跳转至修改页")
	@RequestMapping(value = "/toUpdate", method = RequestMethod.GET)
    public String toUpdate(@ApiParam(required = true, name = "id", value = "id编号")
                               @RequestParam("id") Integer id,
                           Model model) {
        ServiceLocationEntity entity = serviceLocationService.queryObject(id);
        model.addAttribute("entity", entity);

        return "bus/servicelocation/addOrUpdateServiceLocation";
    }
	
    /**
     * 修改
     */
    @ApiOperation(value = "修改信息", notes = "修改信息")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public ApiRes update(ServiceLocationEntity entity) {
        serviceLocationService.update(entity);
        return ApiRes.SUCCESS;
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除信息", notes = "删除信息")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public ApiRes delete(@ApiParam(required = true, name = "ids", value = "id编号（多个之间以逗号隔开）")
                                      @RequestParam("ids") Integer[] ids) {
        serviceLocationService.deleteBatch(ids);
        return ApiRes.SUCCESS;
    }

}
